﻿using System;
using Assist;
using Autodesk.Revit.DB;

namespace YRevitJig
{
	public class ViewAssist
	{
		public static bool ViewValidating(Document doc, View activeView)
		{
			bool flag = activeView.GetType() == typeof(ViewPlan);
			bool result;
			if (flag)
			{
				ViewPlan viewPlan = activeView as ViewPlan;
				bool flag2 = viewPlan.SketchPlane == null;
				if (flag2)
				{
					Plane plane = RevitVersionFuncs.CreatePlanByOriginAndBasis(viewPlan.Origin, viewPlan.RightDirection, viewPlan.UpDirection);
					Transaction transaction = new Transaction(doc);
					transaction.Start("new sketchPlane");
					activeView.SketchPlane = SketchPlane.Create(doc, plane);
					transaction.Commit();
				}
				result = true;
			}
			else
			{
				bool flag3 = activeView.GetType() == typeof(ViewSection);
				if (flag3)
				{
					ViewSection viewSection = activeView as ViewSection;
					bool flag4 = viewSection.SketchPlane == null;
					if (flag4)
					{
						Plane plane2 = RevitVersionFuncs.CreatePlanByOriginAndBasis(viewSection.Origin, viewSection.RightDirection, viewSection.UpDirection);
						Transaction transaction2 = new Transaction(doc);
						transaction2.Start("new sketchPlane");
						activeView.SketchPlane = SketchPlane.Create(doc, plane2);
						transaction2.Commit();
					}
					result = true;
				}
				else
				{
					result = false;
				}
			}
			return result;
		}
	}
}
